package com.system.orders.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.system.common.bean.Payment;
import com.system.common.service.IPaymentService;
import com.system.common.util.Result;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/payment")
public class PaymentController {

    @DubboReference
    private IPaymentService paymentService;

    @PostMapping("/add")
    public Result add(@RequestBody Payment payment) {
        paymentService.addPayment(payment);
        return Result.ok("添加支付记录成功");
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        paymentService.deletePayment(id);
        return Result.ok("删除支付记录成功");
    }

    @PutMapping("/update")
    public Result update(@RequestBody Payment payment) {
        paymentService.updatePayment(payment);
        return Result.ok("修改支付记录成功");
    }

    @PutMapping("/updateStatus")
    public Result updateStatus(@RequestBody Payment payment) {
        paymentService.updateStatus(payment.getId(), payment.getPaystatus());
        return Result.ok("修改支付状态成功");
    }

    @GetMapping("/list")
    public Result list() {
        return Result.ok("获取支付记录列表成功", paymentService.getPaymentList());
    }

    @GetMapping("/page")
    public Result page(Payment payment,
                       @RequestParam(defaultValue = "1") Integer pageNum,
                       @RequestParam(defaultValue = "10") Integer pageSize) {
        return Result.ok("获取支付记录分页成功", paymentService.getPage(payment, new Page<>(pageNum, pageSize)));
    }

    @GetMapping("/getPaymentById/{id}")
    public Result getPaymentById(@PathVariable Integer id) {
        return Result.ok("获取支付记录成功", paymentService.getPaymentById(id));
    }

    @GetMapping("/getPaymentByOrderNo/{orderno}")
    public Result getPaymentByOrderNo(@PathVariable String orderno) {
        return Result.ok("获取支付记录成功", paymentService.getPaymentByOrderNo(orderno));
    }
}
